package com.briup.day06;

public class Test_binarySearch {
    public static void main(String[] args) {
        int[] arr=new int[]{1,3,7,10,12,25,37};
       int index= binarySearch(arr,12);
        System.out.println(index);
    }
    public static int binarySearch(int[] arr,int value){
        int left=0;
        int right=arr.length-1;
        while(left<=right){
            int mid = (left+right)/2;
            if(value==arr[mid]){
                return mid;
            }else if(value>arr[mid]){
                left=mid+1;
            }else{
                right=mid-1;
            }
//找2的话left = mid + 1 = 0 + 1 = 1
//此时 left=1，right=0
        }
        return -1;
    }

}
